
using System;
using System.Collections.Generic;
using System.Text;
using SharpMud.LPC;

namespace SharpMud.Net.Intermud3.Packets
{
    /// <summary>
    /// Represents the Intermud3's "EmoteTo" packet, used to send private messages from one user to another,
    /// in emote format, with the sender's replaced by the "%s" token.
    /// </summary>
    public class EmoteTo : GenericPacket
    {
        private const string _PacketType = "emoteto";

        protected EmoteTo()
            : base(new LPC.LpcArray((LpcString)_PacketType, (LpcInteger)5, (LpcString)"", (LpcString)"", (LpcString)"", (LpcString)"", (LpcString)"", (LpcString)""))
        {
        }

        protected EmoteTo(LpcArray data)
            : base(data)
        {
            if (data.Count != 8)
                throw new InvalidPacketException("A 'emoteto' packet requires 8 LpcObject's, to be created.");
        }

        public EmoteTo(string originatorMud, string originatorUsername, string targetMud, string targetUsername, string originatorVisname, string message)
            : base(new LpcArray((LpcString)_PacketType, (LpcInteger)5, (LpcString)originatorMud, (LpcString)originatorUsername, (LpcString)targetMud, (LpcString)targetUsername, (LpcString)originatorVisname, (LpcString)message))
        {
        }

        public virtual string OriginatorVisname
        {
            get
            {
                return (string)((LpcString)(_data[6]));
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                if (_data[6] is LpcString)
                {
                    ((LpcString)_data[6]).Value = value;
                    return;
                }
                else if (_data[6] == null)
                {
                    _data[6] = new LpcString(value);
                    return;
                }
                throw new InvalidOperationException();
            }
        }

        public virtual string Message
        {
            get
            {
                return (string)((LpcString)(_data[7]));
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                if (_data[7] is LpcString)
                {
                    ((LpcString)_data[7]).Value = value;
                    return;
                }
                else if (_data[7] == null)
                {
                    _data[7] = new LpcString(value);
                    return;
                }
                throw new InvalidOperationException();
            }
        }

        public override string PacketType
        {
            get
            {
                return _PacketType;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                if (value.Trim().ToLower() == _PacketType)
                    return;
                else
                    throw new InvalidOperationException("A specific packet-type instance cannot be assigned PacketType's.");
            }
        }

        public static GenericPacket CreatePacket(LpcArray data)
        {
            return new EmoteTo(data);
        }

        static EmoteTo()
        {
            GenericPacket.RegisterPacketType(_PacketType, EmoteTo.CreatePacket);
        }
    }
}


